<!--移动签批->公文详情->发文->index-->
<template>
  <view>
    <van-tabs color="#1989fa" title-active-color="#1989fa" animated swipeable @change="onChange">
      <van-tab title="公文详情" name="gwxq">
        <detail ref="detail" :detailObj1="detailObj1" :proInstId="proInstId" @showRevisionSheet="showRevisionSheet"
                @showFenfaSheet="showFenfaSheet"></detail>
      </van-tab>
      <van-tab title="版式稿纸" name="bsgz">
        <read :detailObj1="detailObj1" :proInstId="proInstId" :extendIdForRelate="extendIdForRelate"
              :fwWordId="fwWordId"></read>
      </van-tab>
      <van-tab title="流转过程" name="lzgc" :key='2'>
        <docProcess :dataList="dataList"></docProcess>
      </van-tab>
    </van-tabs>
    <edit ref="edit" @refreshBtnGroup="refreshBtnGroup" :showEdit="showEdit" @closeEdit="closeEdit"></edit>
    <records @refreshBtnGroup="refreshBtnGroup" :showRecords="showRecords" @closeRecords="closeRecords"
             :paramObject="paramObject"></records>
    <trans ref="trans" :proInstId="proInstId" @refreshBtnGroup="refreshBtnGroup" :showTrans="showTrans"
           @closeTrans="closeTrans" :paramObject="paramObject" :detailObject="detailObj1.detailObj"></trans>
    <more :showShare="showShare" @closeShare="closeShare" :options="barList.slice(4)"></more>
    <generate @refreshBtnGroup="refreshBtnGroup" :showGenerate="showGenerate" @closeGenerate="closeGenerate"
              :generateParamObject="generateParamObject"></generate>
    <issuance :showIssuance="showIssuance" @refreshBtnGroup="refreshBtnGroup" @closeIssuance="closeIssuance"
              :paramObject="paramObject"></issuance>
    <revision ref="revision" :showRevision="showRevision" @closeRevisionSheet="closeRevisionSheet"></revision>
    <fenfa ref="fenfa" :showFenfa="showFenfa"  @closeFenfaSheet="closeFenfaSheet"></fenfa>
    <div style="height: 5rem;" v-if="fromType != 'search'">
      <van-tabbar v-model="active">
        <!-- <van-tabbar-item v-for="(item,index) in barList" v-if="index < 4" :name="item.name" :icon="item.icon" @click="onClick(item.name)">{{item.value}}
        </van-tabbar-item> -->
        <van-tabbar-item v-for="(item,index) in barList" :key="index" v-if="index < 4" :name="item.name"
                         @click="onClick(item.operation)">
          <span>{{ item.value }}</span>
          <template #icon="props">
            <img :src="props.active ? item.iconTab.active : item.iconTab.inactive"/>
          </template>
        </van-tabbar-item>
      </van-tabbar>
    </div>
  </view>
</template>

<script>
import detail from 'pages/admin/components/sendDoc/compo-detail';
import docProcess from 'pages/admin/components/sendDoc/compo-process';
import edit from 'pages/admin/components/sendDoc/compo-edit';
import records from 'pages/admin/components/common/compo-records';
import trans from 'pages/admin/components/sendDoc/compo-trans';
import more from 'pages/admin/components/sendDoc/compo-more';
import generate from 'pages/admin/components/sendDoc/compo-generate';
import issuance from 'pages/admin/components/sendDoc/compo-issuance';
import read from 'pages/admin/components/sendDoc/compo-read';
import revision from 'pages/admin/components/common/compo-revision';
import fenfa from 'pages/admin/components/common/compo-fenfa';
export default {
  components: {
    detail,
    docProcess,
    edit,
    records,
    trans,
    more,
    generate,
    issuance,
    read,
    revision,
    fenfa
  },
  onLoad: async function (option) {
    await this.$onLaunched //解決bug：执行完onLaunch后再执行页面onLoad
    this.userInfo = this.cache.get('userInfo')//从缓存获取用户信息
    //从地址栏获取proInstId
    this.proInstId = option.proInstId
    //fromType==search，说明是从公文搜索页跳转过来，隐藏相关操作按钮
    this.fromType = option.from
    if (this.proInstId != undefined && this.proInstId != '') {
      this.getCaacDetail(this.proInstId)//通过proInstId获取详情
      this.getCaacOpinion(this.proInstId)//获取意见
    }
  },
  created() {

  },
  //文件编辑保存后返回到首页就重新获取文件及附件
  onShow(){
    //延迟调用，防止文件过大PC端没保存上就获取
    setTimeout(() => {
      if(this.util.isNotEmpty(this.extendIdForRelate)){
        this.getCaacBody(this.extendIdForRelate)//获取正文
        this.getCaacAttachment(this.extendIdForRelate)//获取附件
        this.getRelation(this.extendIdForRelate)//获取附加公文
      }
    }, 800)
  },
  data() {
    return {
      fromType: '',//fromType==search，说明是从公文搜索页跳转过来，隐藏相关操作按钮
      //记录对应的tab页数据是否已加载
      gwxqFlag: true,
      bsgzFlag: true,
      lzgcFlag: true,
      extendIdForRelate: '',
      fwWordId: '',
      gwSercet: {},//公文秘书，调退公文秘书接口用参数
      userInfo: {},//当前登录用户信息，目前先从缓存中获取
      proInstId: '',
      tuiGongWen: [],//退公文秘书所需参数，调用listNextActivities接口获得
      endGongWen: [],//结束公文所需参数，调用listNextActivities接口获得
      fwId: '',//发文id
      active: '',
      showEdit: false,
      showRecords: false,
      showTrans: false,
      showShare: false,
      showGenerate: false,
      showIssuance: false,//签发
      barList: [],
      //公文详情
      detailObj1: {
        detailObj: null,//详情
        detailBody: null,//正文
        detailAttachment: null,//附件
        relation: null,//附加公文
        opinion: null,//意见
        optionBtn01: null,//获取签批功能菜单所需要的参数
        optionBtn02: null,//获取签批功能菜单所需要的参数
        optionBtn: null,//签批功能菜单,根据optionBtn01和optionBtn02返回的参数作为请求参数
      },
      dataList: {
        docProcess: {},//流转过程
        signProcess: [],//会签件
      },
      options: [],//更多操作
      //获取签批功能的接口里有
      paramObject: {
        //"bizId":"c7cbc671330d472b94fac967ba7b3840","proInstId":"55d46548585546c9a667796abf640713","configId":"68f6c3cf43aa466f899798691229159b","proDirId":"25ded9cc79b94329beffa78225a077c9","actInstId":"9af5da0ced204e36af9da9cd909394d5","actDefId":"nigao","workitemId":"5de39682f91d423b99b9a3f3e041d4e0","state":null,"isClosed":"2","configCode":"mhj_fw"
      },
      generateParamObject: {
        "fwId": '',
        "fwWord": '',
        "fwWordId": '',
        "fwNum": '',
        "fwYear": ''
      },
      buttonArr: [],    // 要显示的功能按钮
      curActivity: '',  //获取秘书所需参数
      showRevision: false,//显示文档修订记录
      showFenfa: false,//分发组件
    };
  },
  watch: {},

  mounted() {
    //处理页面弹出层初始化
    this.active = 'gwxq'
    this.showEdit = false
    this.showRecords = false
    this.showTrans = false
    this.showShare = false
    this.showGenerate = false
    this.showIssuance = false

    //延迟调用listNextActivities获取下一活动节点信息，
    setTimeout(() => {
      this.listNextActivities()
    }, 5000)
  },
  methods: {
    //显示分发组件
    showFenfaSheet(){
      this.showFenfa = true
    },
    //关闭分发组件
    closeFenfaSheet(userInfo){
      //userInfo: {"userId":["2163","8943"],"userName":["刘xx","刘xx"]}
      this.$refs.detail.initParam(userInfo)
      this.showFenfa = false
    },
    //显示文档修订记录组件
    showRevisionSheet(proInstId) {
      this.showRevision = true
      this.$refs.revision.getDocumentRecordByProInstId(proInstId)
    },
    //关闭文档修订记录组件
    closeRevisionSheet() {
      this.showRevision = false
    },
    //tab 点击事件
    onChange(itemTitle) {
      // this.$toast(itemTitle)
      if (itemTitle == 'gwxq') {//公文详情
        if (this.gwxqFlag) {
          this.getCaacDetail(this.proInstId)
        }
      } else if (itemTitle == 'bsgz') {//版式稿纸
        if (this.bsgzFlag) {
          //TODO 加载版式稿纸
        }
      } else if (itemTitle == 'lzgc') {//流转过程
        if (this.lzgcFlag) {
          this.getCaacDocProcess(this.proInstId)
          this.getListChildSubOperationLogs(this.proInstId)
        }
      }
    },
    //关闭修改公文要素
    closeEdit(showEdit) {
      this.showEdit = false
    },
    //关闭填写意见
    closeRecords(showRecords) {
      this.showRecords = false
    },
    //关闭流转
    closeTrans(showTrans) {
      this.showTrans = false
    },
    //关闭更多操作
    closeShare(item) {
      this.showShare = false
      this.btnFunction(item)
    },

    //关闭生成发文字号
    closeGenerate(showGenerate) {
      this.showGenerate = false
    },
    //关闭签发
    closeIssuance(showIssuance) {
      this.showIssuance = false
    },
    //点击tabbar
    onClick(item) {
      this.btnFunction(item)
    },
    //下边菜单点击功能
    btnFunction(item) {
      //修改公文要素
      if (item == 'xggwys') {
        this.showEdit = true
        this.$refs.edit.editGw(this.proInstId);//调用子组件的方法
      }
      //填写意见
      if (item == 'addReviews') {
        this.showRecords = true
      }
      //会签-填写意见
      if (item == 'txyj') {
        this.showRecords = true
      }
      //流转
      if (item == 'generalMove') {
        this.showTrans = true;
        //调用子组件方法加载数据
        // this.$refs.trans.loadTree();

      }
      //会签件流转
      if (item == 'complete') {
        this.showTrans = true;
        //调用子组件方法加载数据
        // this.$refs.trans.loadTree();
      }
      //更多操作
      if (item == 'more') {

        this.showShare = true
      }
      //生成发文字号
      if (item == 'getFwNum') {
        this.showGenerate = true
      }
      //结束公文
      if (item == 'endProcess') {
        this.endProcess()
      }
      //会签管理
      if (item == 'huiqianManagement') {
        //跳转到会签页面
        uni.navigateTo({
          url: "/pages/admin/send/countersign?proInstId=" + this.proInstId + "&fwId=" + this.extendIdForRelate + "&docTitle="+this.detailObj1.detailObj.title
        })
      }
      //转办
      if (item == 'reassign') {
        this.$toast('转办')
      }
      //退公文秘书
      if (item == 'liuzhuanTuimishu') {
        this.tuiGwmsConfirm()
        // this.$toast('退公文秘书')
      }
      //签发
      if (item == 'review_QianFa') {
        this.showIssuance = true
        // uni.navigateTo({
        // 	url:"/pages/admin/send/sign-send?proInstId="+this.proInstId+"&actInstId="+this.paramObject.actInstId+"&workItemId="+this.paramObject.workitemId
        // })
      }
      //作废
      if (item == 'cancelGw') {
        this.cancelGwConfirm()
      }
      if (item == 'review_TongYi') {
        this.opinionType('1')//1-同意，2-已阅
      }
      if (item == 'review_YiYue') {
        this.opinionType('2')//1-同意，2-已阅
      }
      //本单位会签完毕hqwb
      if (item == 'hqwb') {
        this.hqwbConfirm()
      }

    },

    // 获取要显示的按钮
    async getButtonsData(proInstId, drafterId) {
      let _this = this
      await _this.$http({
        url: _this.$http.adornUrl(`/caac/oa/app/getButtonsData`),
        method: 'get',
        params: _this.$http.adornParams({
          'systemKey': _this.userInfo.systemKey,//固定值
          'systemFlag': _this.userInfo.systemFlag,//固定值
          'proInstId': proInstId,
          'drafterId': ''
        })
      }).then(({data}) => {
        if (data.code == 200) {
          console.log('要显示的按钮--->' + data.data.buttons);
          this.buttonArr = data.data.buttons
        }
      })
    },

    //本单位会签完毕
    hqwbConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      })
              .then(() => {
                // on confirm
                this.jieshuGongWen()//本单位会签完毕和结束公文是同一个接口

              })
              .catch(() => {
                // on cancel
              });
    },
    //结束公文确认弹框
    endProcess() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '确认操作吗?',
      })
              .then(() => {
                this.jieshuGongWen()//结束公文
              })
              .catch(() => {
                // on cancel
              });
    },
    //获取发文待办详情数据
    getCaacDetail(proInstId) {

      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/authority/gljfw/proInstId/` + proInstId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
          // 'systemKey': 'ls_liu',//固定值
          // 'systemFlag': 'yidong'//固定值
        })
      }).then(({data}) => {
        console.log("公文详情: " + JSON.stringify(data));
        if (data.code == 200) {
          //根据字典code获取字典
          _this.detailObj1.detailObj = data.data
          _this.generateParamObject.fwId = data.data.fwId
          _this.generateParamObject.fwWord = data.data.fwWord
          _this.generateParamObject.fwWordId = data.data.fwWordId
          _this.generateParamObject.fwNum = data.data.fwNum
          _this.generateParamObject.fwYear = data.data.fwYear
          _this.fwId = data.data.fwId
          _this.extendIdForRelate = data.data.extendIdForRelate
          _this.fwWordId = data.data.fwWordId
          _this.getCaacBody(_this.extendIdForRelate)//获取正文
          _this.getCaacAttachment(_this.extendIdForRelate)//获取附件
          _this.getRelation(_this.extendIdForRelate)//获取附加公文
          _this.openwfneededdata(_this.fwId, proInstId)

          this.gwxqFlag = false //请求成功后置为false，防止tab切换重新获取数据
        }

      })
    },

    //获取正文数据
    getCaacBody(extendIdForRelate) {
      // proInstId = 'c96d8fbcc1f000011ac1cea035606e10'
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/maintext/proInstId/` + extendIdForRelate),
        method: 'get',
        params: this.$http.adornParams({
          // 'extendIdForRelate': this.proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.detailBody = data.data
        }
        console.log("正文: " + JSON.stringify(_this.detailObj1.detailBody));
      })
    },

    //获取附件数据
    getCaacAttachment(extendIdForRelate) {
      // proInstId = 'c970c796d5300001a2e61ac01170daa0'
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderBy`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': extendIdForRelate,
          'attachTypeId': 'pageBody_uploadFile',
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.detailAttachment = data.data
        }
        console.log("附件: " + JSON.stringify(_this.detailObj1.detailAttachment));
      })
    },

    //获取意见
    getCaacOpinion(proInstId) {
      // proInstId = 'f9525d014c5348fb866daca4879ae905'//TODO 暂时写死
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/approvalwrite`),
        method: 'get',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null) {
            _this.detailObj1.opinion = data.data
          }
        }
        console.log("发文意见: " + JSON.stringify(data));
      })
    },
    //获取附加公文
    getRelation(extendIdForRelate) {
      // proInstId = 'f9525d014c5348fb866daca4879ae905'//TODO 暂时写死
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/mhjComponent/relationfile/relation`),
        method: 'get',
        params: this.$http.adornParams({
          'docId': extendIdForRelate,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        //[{"id":"1c0962f8839d46f792f84e5c89c96f14","title":"ppap","relateDocId":"4ec205b8334446f9b932d0fcb3896bc8","proInstId":"4ec205b8334446f9b932d0fcb3896bc8"},{"id":"2f4aa437ecba4c748bff911f03667147","title":"py","relateDocId":"86d30c881c494b468534685bb0746174","proInstId":"86d30c881c494b468534685bb0746174"}]
        if (data.code == 200) {
          if (data.data != null) {
            _this.detailObj1.relation = data.data
          }
        }
        console.log("附加公文: " + JSON.stringify(data));
      })
    },

    //获取流转过程
    getCaacDocProcess(proInstId) {
      var _this = this
      this.$httploading({/// /caac/oa/mhjcomponent/processtrack/flowController/listoperationlogs
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listProInstIdOperationLogs?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("流转过程data: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.dataList.docProcess = data.data
          this.lzgcFlag = false
        }

      })
    },
    //获取子流转过程
    getListChildSubOperationLogs(proInstId) {
      var _this = this
      this.$httploading({/// /caac/oa/mhjcomponent/processtrack/flowController/listoperationlogs
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listChildSubOperationLogs?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("子流转过程data: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.dataList.signProcess = data.data
        }

      })
    },

    //获取签批功能菜单optionBtn01
    openwfneededdata(fwId, proInstId) {
      // fwId = 'abd03f22703a4d2da09b17d9b119b405'//TODO 测试用，写死
      // proInstId='0708bdf2d218451d8da6c01bdbaf2ade'
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/comm/comm/openwfneededdata`),
        method: 'get',
        params: this.$http.adornParams({
          'id': fwId,//发文详情返回的fwId
          'proInstId': proInstId,//发文详情返回的proInstId
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.optionBtn01 = data.data
          _this.paramObject = data.data
          // _this.opinionObj.workItemId = data.data.workitemId//填写意见接口用
          // _this.opinionObj.actInstId = data.data.actInstId//填写意见接口用
          console.log("签批功能菜单optionBtn01: " + JSON.stringify(data.data));
          _this.getRoleTypesAndActInst(data.data.configId, proInstId)
          //获取秘书所需参数
          if (data.data.actDefId == 'otherTask') {
            this.initSendNextInfo(proInstId)
          }
        }

      })
    },
    initSendNextInfo(proInstId) {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/authority/gljfw/initSendNextInfo`),
        method: 'get',
        params: {
          'systemKey': this.cache.get('userInfo').systemKey,//固定值
          'systemFlag': this.cache.get('userInfo').systemFlag,//固定值
          'data': this.$http.adornData({
            'proInstId': proInstId,//固定值
            'canGotoSpecialDraft': 'true'//固定值
          })
        }
      }).then(({data}) => {
        if (data.code == 200) {
          this.curActivity = data.data.currentActivity
        }

      })
    },

    //获取签批功能菜单optionBtn02
    getRoleTypesAndActInst(configId, proInstId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/getRoleTypesAndActInst`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,//发文详情返回的proInstId
          'configId': configId,//openwfneededdata()返回的configId
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.optionBtn02 = data.data
          console.log("签批功能菜单optionBtn02: " + JSON.stringify(data.data));
          _this.initActivity()

        }

      })
    },
    // async getDicByDictCodes(){
    // 	var obj =await this.dict.getDicByDictCodes('reviewType')
    // 	return obj
    // },

    /**
     * 子页面流转后调用此方法刷新功能按钮
     * @param {Object} item Boolean值，为true 就刷新
     */
    refreshBtnGroup(item) {
      console.log("shuaxina " + item)
      if (item) {
        this.getCaacDetail(this.proInstId)
        this.getCaacOpinion(this.proInstId)
      }
    },
    //获取签批功能菜单
    async initActivity() {
      // 获取要显示的功能按钮
      await this.getButtonsData(this.proInstId, this.detailObj1.detailObj.drafterId)
      const _this = this
      let option01 = this.detailObj1.optionBtn01
      let option02 = this.detailObj1.optionBtn02.actInstList[0] //TODO 次处返回了数组格式，需和pc端确认
      // console.log("option02===: " + JSON.stringify(option02));
      await this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/initActivity`),
        method: 'post',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data': this.$http.adornData({
            'configId': option01.configId,//openwfneededdata()返回的configId
            'configCode': option01.configCode,
            'proDirId': option01.proDirId,
            'actDefId': option01.actDefId,
            'wfmRoleTypes': option02.wfmRoleTypes,
            'proInstId': option01.proInstId,
            'actInstId': option01.actInstId,
            'workitemId': option01.workitemId,
            'wfmInitPageType': 'running',
            'bizId': option01.bizId
          }),

        })
      }).then(({data}) => {
        console.log("data---->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.detailObj1.optionBtn = data.data
          var operations = data.data.qualifiedOperations
          // console.log(operations);
          _this.barList = [] //重置为空
          if (operations != null && operations.length > 0) {
            //TODO 还需判断其他类型的按钮
            for (let i = 0; i < operations.length; i++) {
              //修改公文要素
              if (operations[i].operation == 'xggwys') {
                _this.barList.push({
                  name: '修改公文要素',
                  operation: 'xggwys',
                  icon: 'static/imgs/icon/icon-xggwys.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-xggwys-active.png',
                    inactive: 'static/imgs/icon/icon-xggwys.png'
                  },
                  value: operations[i].operationName,
                  sort: 10
                })
              }
              //填写意见
              if (operations[i].operation == 'addReviews') {
                _this.barList.push({
                  name: '填写意见',
                  operation: 'addReviews',
                  icon: 'static/imgs/icon/icon-opinion.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-opinion-active.png',
                    inactive: 'static/imgs/icon/icon-opinion.png'
                  },
                  value: operations[i].operationName,
                  sort: 1
                })
              }
              //会签-填写意见
              if (operations[i].operation == 'txyj') {
                _this.barList.push({
                  name: '填写意见',
                  operation: 'txyj',
                  icon: 'static/imgs/icon/icon-opinion.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-opinion-active.png',
                    inactive: 'static/imgs/icon/icon-opinion.png'
                  },
                  value: operations[i].operationName,
                  sort: 1
                })
              }
              //流转
              if (operations[i].operation == 'generalMove') {
                _this.barList.push({
                  name: '流转',
                  operation: 'generalMove',
                  icon: 'static/imgs/icon/icon-transfer.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value: operations[i].operationName,
                  sort: 3
                })
              }
              //会签-流转
              if (operations[i].operation == 'complete') {
                _this.barList.push({
                  name: '流转',
                  operation: 'complete',
                  icon: 'static/imgs/icon/icon-transfer.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value: operations[i].operationName,
                  sort: 3
                })
              }

              //结束公文
              if (operations[i].operation == 'endProcess') {
                _this.barList.push({
                  name: '结束公文',
                  operation: 'endProcess',
                  icon: 'static/imgs/icon/icon-finished.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-finished-active.png',
                    inactive: 'static/imgs/icon/icon-finished.png'
                  },
                  value: operations[i].operationName,
                  sort: 11
                })
              }

              //生成发文字号
              if (operations[i].operation == 'getFwNum') {
                _this.barList.push({
                  name: '生成发文字号',
                  operation: 'getFwNum',
                  icon: 'static/imgs/icon/icon-generate.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-generate-active.png',
                    inactive: 'static/imgs/icon/icon-generate.png'
                  },
                  value: operations[i].operationName,
                  sort: 7
                })
              }
              //会签管理
              if (operations[i].operation == 'huiqianManagement') {
                _this.barList.push({
                  name: '会签管理',
                  operation: 'huiqianManagement',
                  icon: 'static/imgs/icon/icon-sign.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-sign-active.png',
                    inactive: 'static/imgs/icon/icon-sign.png'
                  },
                  value: operations[i].operationName,
                  sort: 4
                })
              }
              //转办
              // if(operations[i].operation =='reassign'){
              // 	_this.barList.push({
              // 		name:operations[i].operationName,
              // 		operation:'reassign',
              // 		icon:'static/imgs/icon/icon-handover.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
              // 		iconTab:{
              // 			active: 'static/imgs/icon/icon-handover-active.png',
              // 			inactive: 'static/imgs/icon/icon-handover.png'
              // 		},
              // 		value:operations[i].operationName,
              // 	})
              // }
              //退公文秘书
              if (operations[i].operation == 'liuzhuanTuimishu') {
                _this.barList.push({
                  name: '退公文秘书',
                  operation: 'liuzhuanTuimishu',
                  icon: 'static/imgs/icon/icon-tuigwms.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value: operations[i].operationName,
                  sort: 2
                })
              }
              //签发
              if (operations[i].operation == 'review_QianFa') {
                _this.barList.push({
                  name: '签发',
                  operation: 'review_QianFa',
                  icon: 'static/imgs/icon/icon-qianfa.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-qianfa-active.png',
                    inactive: 'static/imgs/icon/icon-qianfa.png'
                  },
                  value: operations[i].operationName,
                  sort: 8
                })
              }

              //作废
              if (operations[i].operation == 'cancelGw') {
                _this.barList.push({
                  name: '作废',
                  operation: 'cancelGw',
                  icon: 'static/imgs/icon/icon-invalid.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-invalid-active.png',
                    inactive: 'static/imgs/icon/icon-invalid.png'
                  },
                  value: operations[i].operationName,
                  sort: 12
                })
              }
              //同意
              if (operations[i].operation == 'review_TongYi') {
                _this.barList.push({
                  name: '同意',
                  operation: 'review_TongYi',
                  icon: 'static/imgs/icon/icon-agree.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value: operations[i].operationName,
                  sort: 5
                })
              }
              //已阅
              if (operations[i].operation == 'review_YiYue') {
                _this.barList.push({
                  name: '已阅',
                  operation: 'review_YiYue',
                  icon: 'static/imgs/icon/icon-yy.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-yy-active.png',
                    inactive: 'static/imgs/icon/icon-yy.png'
                  },
                  value: operations[i].operationName,
                  sort: 6
                })
              }
              //本单位会签完毕
              if (operations[i].operation == 'hqwb') {
                _this.barList.push({
                  name: '本单位会签完毕',
                  operation: 'hqwb',
                  icon: 'static/imgs/icon/icon-agree.png',//供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  iconTab: {
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value: operations[i].operationName,
                  sort: 9
                })
              }

            }
            // 功能按钮筛选
            if (this.util.isNotEmpty(this.buttonArr)) {
              let newBarList = []
              this.buttonArr.filter((b, index) => this.buttonArr.indexOf(b) === index).forEach((item) => {
                let arr = this.barList.filter(t => t.operation == item)
                if (arr != null && arr.length > 0) {
                  newBarList.push(arr[0])
                }
              })
              this.barList = newBarList
            } else {
              this.barList = []//如果获取到的按钮为空，则置空
            }
            //大于三个添加更多按钮,第四个按钮为更多操作
            if (_this.barList.length > 3) {
              _this.barList.sort((a, b) => a.sort - b.sort)

              var more = {
                name: '更多',
                operation: 'more',
                icon: 'static/imgs/icon/icon-more.png',
                iconTab: {
                  active: 'static/imgs/icon/icon-more-active.png',
                  inactive: 'static/imgs/icon/icon-more.png',
                },
                value: '更多操作',
              }
              _this.barList.splice(3, 0, more);
            }
          }


        } else {
          console.log("出错了: " + JSON.stringify(data));
        }

      })
    },

    //结束公文
    jieshuGongWen() {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({
            fwForm: this.detailObj1.detailObj,//详情
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'proInstId': _this.paramObject.proInstId,
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'nextActivities': _this.endGongWen
            },

          })
        }
      }).then(({data}) => {
        console.log("结束公文data-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast('操作成功')
          uni.redirectTo({
            url: '/pages/admin/send/signList'
          })

        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    //获取流转范围
    listNextActivities() {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
        method: 'post',
        params: {
          //固定值
          'data': this.$http.adornData({
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'wfmInitPageType': 'running'
            }
          })
        }
      }).then(({data}) => {
        // console.log("结束公文参数data===>>>>: " + JSON.stringify(data));
        if (data.code == 200) {
          let nextActDefIds = data.data.nextActDefIds
          let currentActDefId = data.data.actDefId

          if (nextActDefIds) {
            for (var i = 0; i < nextActDefIds.length; i++) {
              if ("csgwmszz" == nextActDefIds[i].actDefId && currentActDefId.indexOf("scsldsp") > -1) {
                _this.tuiGongWen.push(nextActDefIds[i])
              } else if ("sjzbsgzz" == nextActDefIds[i].actDefId && currentActDefId.indexOf("sjldsh") > -1) {
                _this.tuiGongWen.push(nextActDefIds[i])
              } else if ("hqjsr" == nextActDefIds[i].actDefId && currentActDefId.indexOf("scsldhq") > -1) {
                _this.tuiGongWen.push(nextActDefIds[i])
              }
              // _this.tuiGongWen.push(nextActDefIds[0])
              if (nextActDefIds[i].actType == 'end') {
                _this.endGongWen.push(nextActDefIds[i])
              }
            }
          }
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }
      })
    },
    //退公文秘书
    tuiGwmsConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      })
              .then(() => {
                // on confirm
                this.getJldMsRelate()

              })
              .catch(() => {
                // on cancel
              });
    },
    //同意或已阅1-同意，2-已阅
    opinionType(type) {
      // console.log("this.paramObject: " + JSON.stringify(this.paramObject));
      this.$dialog.confirm({
        title: '系统提示',
        message: '确定要操作吗?',
      }).then(() => {
        // on confirm
        if (this.util.isNotEmpty(this.paramObject)) {
          if (type == '1') {//1-同意
            this.message = '同意'
            this.opiniontype = 'jldReview'
            this.saveopinion()
          } else {
            this.message = '已阅'
            this.opiniontype = 'jldReview'
            this.saveopinion()
          }
        }
      })
              .catch(() => {
                // on cancel
              });

    },
    //填写意见接口
    saveopinion() {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/saveopinion?systemKey=` + this.cache.get('userInfo').systemKey + `&systemFlag=` + this.cache.get('userInfo').systemFlag),
        method: 'post',
        data: this.$http.adornData({
          'proInstId': _this.paramObject.proInstId,//发文详情返回的proInstId
          'workItemId': _this.paramObject.workitemId,//
          'actInstId': _this.paramObject.actInstId,//
          'opiniontype': _this.opiniontype,
          'opinion': _this.message,
          'isApproval': '1',//核稿状态，默认传1
          // 'systemKey': 'jb_sun',//固定值
          // 'systemFlag': 'yidong',//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.$toast('意见填写成功')
          this.refreshBtnGroup(true)
        } else {
          this.$toast(data.message + ' code:' + data.code)
        }

      })
    },
    //作废
    cancelGwConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      })
              .then(() => {
                // on confirm
                this.cancelGw()

              })
              .catch(() => {
                // on cancel
              });
    },
    //作废公文
    cancelGw() {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/abortApplictionController/abortApplication`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({
            'configId': _this.paramObject.configId,
            'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
            'proInstId': _this.paramObject.proInstId,
            'actInstId': _this.paramObject.actInstId,//
            'workitemId': _this.paramObject.workitemId,
            'gwId': this.fwId,
            'title': this.detailObj1.detailObj.title
          }),
        }
      }).then(({data}) => {
        console.log("作废结果-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast("操作成功")
          //作废后还需调另外两个接口
          _this.canceGwUpdateDraftStatus()
          _this.canceGwDeleteWordBiz()
          uni.redirectTo({
            url: '/pages/admin/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })

    },
    //作废-更新状态
    canceGwUpdateDraftStatus() {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/updateDraftStatus`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'id': this.proInstId
        })
      }).then(({data}) => {
        //data: {"code":200,"data":{"userId":"3961"},"message":null}
        console.log("作废UpdateDraftStatus()--->data: " + JSON.stringify(data));
        if (data.code == 200) {

        }

      })

    },
    //作废-更新状态
    canceGwDeleteWordBiz() {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fw/deleteWordBiz`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'fwId': this.fwId
        })
      }).then(({data}) => {
        //data: {"code":200,"data":{"userId":"3961"},"message":null}
        console.log("作废DeleteWordBiz()-->data: " + JSON.stringify(data));
        // if(data.code==200){
        // }

      })

    },
    //先获取这篇文的秘书
    getJldMsRelate() {
      let actDefId = this.paramObject.actDefId
      if(this.paramObject.actDefId === "otherTask"){
        actDefId = this.curActivity
      }
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/authority/gljfw/getms/` + actDefId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        //data: {"code":200,"data":{"userId":"3961"},"message":null}
        console.log("获取这篇文的秘书-->data: " + JSON.stringify(data));
        if (data.code == 200) {
          if (JSON.stringify(data.data) != "{}") {
            this.gwSercet = data.data
            this.tuiGwms()
          } else {
            this.$toast('该领导未配置秘书，需配置！')
          }
        }


      })
    },
    //退公文秘书操作
    tuiGwms() {
      if (this.util.isEmpty(this.gwSercet)) {
        this.$toast('该领导未配置秘书，需配置！')
        return
      }
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/gotoActivity`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({

            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'proInstId': _this.paramObject.proInstId,
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'nextActivities': _this.tuiGongWen,
              'formData': {
                fwForm: this.detailObj1.detailObj,//详情

              },
              "gotoResourceIds": "user:" + this.gwSercet.userId,
              'gotoActDefId': 'otherTask'
            },
          })
        }
      }).then(({data}) => {
        console.log("退公文秘书返回结果-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast("操作成功")
          // 发送通知
          let messageUserIds = this.gwSercet.userId;
          let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/admin/send/index?proInstId=" + this.paramObject.proInstId;
          this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
              this.detailObj1.detailObj.title, "发文", linkUrl);
          uni.redirectTo({
            url: '/pages/admin/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },


  },
};
</script>

<style scoped>

</style>
